886C - Petya and Catacombs - CodeForces Solution


dsu greedy implementation trees *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define FOR_(i, s, n) for(int i = s; i < n; ++i)
#define FOR(i, n) FOR_(i, 0, n)
#define FORR(x, a) for(auto &x : a)
#define IN(x) FORR(y, x) cin >> y;
#define OUT(a) FORR(x, a) cout << x << " "; cout << "\n";
#define OUTM(m) FORR(x, m) cout << x.first << " " << x.second << "\n";
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ld = long double;

int main(){
    FAST
    int n, x;
    cin >> n;
    int ans = 1;
    set<int> was;
    was.insert(0);
    FOR(i, n){
        cin >> x;
        if (was.count(x)) was.erase(x);
        else ++ans;
        was.insert(i + 1);
    }
    cout << ans;
    return 0;
}


Comments

Submit
0 Comments
More Questions

1721A - Image
1180C - Valeriy and Deque
557A - Ilya and Diplomas
1037D - Valid BFS
1144F - Graph Without Long Directed Paths
1228A - Distinct Digits
355B - Vasya and Public Transport
1230A - Dawid and Bags of Candies
1530A - Binary Decimal
1472D - Even-Odd Game
441C - Valera and Tubes
1328E - Tree Queries
265A - Colorful Stones (Simplified Edition)
296A - Yaroslav and Permutations
967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh